package com.hksj.Intelligentmanagement.controller;


import com.hksj.Intelligentmanagement.common.Rest;
import com.hksj.Intelligentmanagement.common.Result;
import com.hksj.Intelligentmanagement.dto.RegionDTO;
import com.hksj.Intelligentmanagement.service.ReadHandNumbnessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@Api(tags = "手动同步手麻数据")
@RestController
@RequestMapping("/api/readHandNumbness")
public class ReadHandNumbnessController {
    @Autowired
    private ReadHandNumbnessService readHandNumbnessService;

    @Autowired
    private DataSource dataSource;

    @ApiOperation(value = "卫宁手麻数据同步")
    @PostMapping("/readAllSensors")
    public Result readAllSensors() {
        readHandNumbnessService.startSync(); // 触发同步
        return Result.ok("手动同步手麻数据成功");
    }

    @ApiOperation(value = "卫宁测试查询")
    @PostMapping("/queryTestForWN")
    public Rest queryTestForWN() {
        List<Map<String,Object>> result = readHandNumbnessService.queryTestForWN();
        return Rest.ok(result);
    }

    @ApiOperation(value = "连接信息查询")
    @GetMapping("/dbinfo")
    public String getDbInfo() throws SQLException {
        Connection conn = dataSource.getConnection();
        DatabaseMetaData metaData = conn.getMetaData();
        return "Database Product Name: " + metaData.getDatabaseProductName() +
                ", Version: " + metaData.getDatabaseProductVersion();
    }
}
